<?php
require_once(OC::$SERVERROOT . "/apps/reports/lib/helper.php");
require_once(OC::$SERVERROOT . "/apps/reports/lib/reports.php");

if (!PFactory::isMasterUser()) {
   echo '您无权访问该资源';
   exit();
}

$model = new PReportsModelReports();
$summary = $model->getSummary();

if ($summary === false) {
   jexit('<div class="yahei large noreportsdata">' . ($model->getError() ? $model->getError() : '系统错误') . '</div>');
}

$tmpl = new OCP\Template('reports', 'part.reports.resumechart', '');
$tmpl->assign('summary', $summary);
?>

<div class="rep_resumefrom" style="margin-top:20px;" id="anchor_trend">
   <h5><b>趋势情况</b></h5>
   <div class="rep_datashow">
      <span><i class="c1"></i> 新增简历<b style="margin-right:10px;"><?=$summary['date']['total']['dupResume']?></b>(不重复<b><?=$summary['date']['total']['resume']?></b>)</span>
      <em></em>
      <span><i class="c2"></i> 进入面试<b><?=$summary['date']['total']['event']?></b></span>
      <em></em>
      <span><i class="c3"></i> 发offer<b><?=$summary['date']['total']['offer']?></b></span>
      <em></em>
      <span><i class="c4"></i> 入职<b><?=$summary['date']['total']['entry']?></b></span>
   </div>

   <div class="putcanvas">
      <div id="dateLine" style="height:215px; width:100%;"></div>
   </div>
</div>

<?php $tmpl->printpage(); ?>

<script type="text/javascript">
$(document).ready(function(){
   var summary = <?=json_encode($summary)?>;
   var charts = new Array();
   $(window).unbind('resize');

   if($('#dateLine').length > 0) {
      charts[charts.length++] = $.jqplot('dateLine',  summary.date.lines.data, {
         seriesColors: [ '#999999', '#06aaff', '#5fcb17', '#d9a300' ],
         axes:{
            xaxis:{
               renderer: $.jqplot.CategoryAxisRenderer,
               ticks: summary.date.lines.ticks
            },
            yaxis:{
               min: 0,
               max: summary.date.lines.max,
               tickInterval : summary.date.lines.tickInterval,
               tickOptions: {formatString: '%d'}
            }
         },
         seriesDefaults: {
            shadow:false,
            lineWidth:1.5,
            markerOptions:{
               shadow:false,
            },
         },
         series:[
            {shadow: false,markerOptions: { style:"filledCircle" }},
            {shadow: false,markerOptions: { style:"filledCircle" }},
            {shadow: false,markerOptions: { style:"filledCircle" }},
            {shadow: false,markerOptions: { style:"filledCircle" }}
         ],
         highlighter: {
            show: true,
            sizeAdjust: 7.5,
            tooltipAxes: 'y',
            tooltipSeparator: ' - ',
            useAxesFormatters: true
         },
         cursor: {
            show: false
         },
         grid: {
            drawGridLines: false,        // wether to draw lines across the grid or not.
            gridLineColor: '#e9e9e9',   // *Color of the grid lines.
            background: '#ffffff',      // CSS color spec for background color of grid.
            borderColor: '#333333',     // CSS color spec for border around grid.
            borderWidth: 0.5,           // pixel width of border around grid.
            shadow: false,               // draw a shadow for grid.
            shadowAngle: 45,            // angle of the shadow.  Clockwise from x axis.
            shadowOffset: 1.5,          // offset from the line of the shadow.
            shadowWidth: 2,             // width of the stroke for the shadow.
            shadowDepth: 2,             // Number of strokes to make when drawing shadow.
            shadowAlpha: 0.07,        // Opacity of the shadow
         }
      });
   }

   $('.sourcePie').each(function(){
      var xtype = $(this).data('xtype');
      $.jqplot ($(this).attr('id'), [summary.source.pies[xtype]['data']], {
         seriesColors: summary.source.pies[xtype]['colors'],
         seriesDefaults: {
            // Make this a pie chart.
            renderer: jQuery.jqplot.PieRenderer,
            rendererOptions: {
               // Put data labels on the pie slices.
               // By default, labels show the percentage of the slice.
               dataLabels: summary.source.pies[xtype]['labels'],
               showDataLabels: true,
               diameter: 118,         // padding between pie and neighboring legend or plot margin.
               sliceMargin: 2,     // gap between slices.
               fill: true,         // render solid (filled) slices.
               startAngle: -180,
               shadow: false,
               shadowOffset: 2,    // offset of the shadow from the chart.
               shadowDepth: 5,     // Number of strokes to make when drawing shadow.  Each stroke
                                   // offset by shadowOffset from the last.
               shadowAlpha: 0.07,   // Opacity of the shadow
               dataLabelPositionFactor:1.3,
               dataLabelThreshold:0
               //dataLabelFormatString:'%.1f%',
            }
         },
         // Custom labels for the series are specified with the "label"
         // option on the series option.  Here a series option object
         // is specified for each series.
         legend: {
            show:false,
            location: 'e'
         },
         grid: {
            drawGridLines: false,        // wether to draw lines across the grid or not.
            gridLineColor: '#d3d3d3',   // *Color of the grid lines.
            background: '#ffffff',      // CSS color spec for background color of grid.
            borderColor: '#d3d3d3',     // CSS color spec for border around grid.
            borderWidth: 0,           // pixel width of border around grid.
            shadow: false,               // draw a shadow for grid.
         }
      });
   });

   var drawResumeDonut = function(target){
      var wtype = $(target).data('wtype');
      var xtype = $(target).data('xtype');

      $.jqplot($(target).attr('id'), [summary.resumeParse.donuts[wtype][xtype]['data']], {
         seriesColors: summary.resumeParse.donuts[wtype][xtype]['colors'],
         seriesDefaults: {
            // make this a donut chart.
            renderer:$.jqplot.DonutRenderer,
            rendererOptions:{
               shadow: false,
               diameter: 118,
               thickness: 13, 
               // Donut's can be cut into slices like pies.
               sliceMargin: 2,
               // Pies and donuts can start at any arbitrary angle.
               startAngle: -180,
               showDataLabels: true,
               // By default, data labels show the percentage of the donut/pie.
               // You can show the data 'value' or data 'label' instead.
               dataLabels: summary.resumeParse.donuts[wtype][xtype]['labels'],
               dataLabelPositionFactor:2.3,
               dataLabelThreshold:0
               //dataLabelFormatString:'%s%',
            }
         },
         grid: {
            drawGridLines: false,        // wether to draw lines across the grid or not.
            gridLineColor: '#d3d3d3',   // *Color of the grid lines.
            background: '#ffffff',      // CSS color spec for background color of grid.
            borderColor: '#d3d3d3',     // CSS color spec for border around grid.
            borderWidth: 0,           // pixel width of border around grid.
            shadow: false,               // draw a shadow for grid.
         },
         legend: {
            show:false,
            location: 'ne',
            border: '0',
            background: '#'
         }
      });
   }

   $('.rep_detailtable .resumeDonut.show').each(function(){
      drawResumeDonut($(this));
   });

   $('.rep_resumefrom').on('click', '.resumeparse', function(){
      var anchor = $($(this).data('anchor'));
      var target = $($(this).data('target'));
      if ($(this).prop('checked')) {
         $(this).closest(".checkbox").addClass("checkedbox");
         target.insertAfter('#resumeParseTitle').show().siblings('.noItem').hide().closest('.rep_detailtable').show();
         $('.resumeDonut', target).each(function(){
            drawResumeDonut($(this));
         });
         //if ($('.rep_resumefrom .resumeparse:checked').length <=1)
         if(anchor.length > 0)
            $('html,body').animate({scrollTop:anchor.offset().top-175},1000);
      } else {
         $(this).closest(".checkbox").removeClass("checkedbox");
         target.hide();
         if ($('.rep_resumefrom .resumeparse:checked').length <=0)
            target.siblings('.item').hide().siblings('.noItem').show();
      }
   });

   $(window).resize(function(){
      $.each(charts, function(i, c){
         c.replot( { resetAxes: { xaxis: true } } );
      });
   });
});
</script>